package com.steven.ourcontest.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.ClassicsHeader
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import io.reactivex.disposables.CompositeDisposable

abstract class BaseFragment: Fragment() {
    protected val disposables: CompositeDisposable = CompositeDisposable()
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return getViewId()?.let {
            inflater.inflate(it,container,true)
        }
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initSmartRefresh()?.let {
            it.setEnableLoadMore(false)
            it.setEnableRefresh(true)
            it.setRefreshHeader(ClassicsHeader(context))
        }
    }

    override fun onDestroy() {
        disposables.clear()
        super.onDestroy()
    }

    abstract fun getViewId():Int?

    open fun initSmartRefresh(): SmartRefreshLayout? {
        return null
    }

    open fun login(){

    }

    open fun logout(){

    }
}